//
//  HPClassView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/4.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "HPClassView.h"
#import "SYNoLabel.h"

@interface HPClassView ()

@property (strong, nonatomic) SYNoLabel *notLab; //没有数据提示

@end


@implementation HPClassView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self initOption];
        [self layout];
    }
    return self;
}
- (UIView *)top_view{
    if (!_top_view) {
        UIView *view = [[UIView alloc]init];
        view.backgroundColor = [UIColor whiteColor];
        _top_view = view;
    }
    return _top_view;
}
- (UIImageView *)leftImageView{
    if (!_leftImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"class_home"];
        _leftImageView = imageView;
    }
    return _leftImageView;
}
- (UILabel *)work_label{
    if (!_work_label) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"课程";
        _work_label = label;
    }
    return _work_label;
}
- (MinButtonViewBtn *)menu_Btn{
    if (!_menu_Btn) {
        MinButtonViewBtn *btn = [[MinButtonViewBtn alloc]initWithFrame:CGRectMake(0, 0, 0, 0) andType:ButtonImageInRight];
        btn.bottomLabel.text = @"";
        btn.topImage.image = [UIImage imageNamed:@"time_buke"];
        [btn.topImage mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@20);
            make.height.equalTo(@20);
        }];
        [btn addTarget:self action:@selector(arrow_click) forControlEvents:UIControlEventTouchUpInside];
        _menu_Btn = btn;
    }
    return _menu_Btn;
}
- (void)initSubView{
    [self addSubview:self.top_view];
    [_top_view addSubview:self.leftImageView];
    [_top_view addSubview:self.work_label];
    [_top_view addSubview:self.menu_Btn];
    [self addLittleSubView];
    
    self.notLab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self];
    
    
}
- (void)initOption{
    self.backgroundColor = [UIColor whiteColor];
}
- (void)layout{
    [_top_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0);
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.height.equalTo(@38);
    }];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@17);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.width.equalTo(@20);
        make.height.equalTo(@20);
    }];
    [_work_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftImageView.mas_right).offset(13);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.width.equalTo(@60.5);
        make.height.equalTo(@15.0);
    }];
    [_menu_Btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.top_view.mas_right).offset(-15);
        make.centerY.equalTo(self.top_view.mas_centerY);
        make.width.equalTo(@120);
        make.height.equalTo(@20);
    }];
    
    [self.notLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(400*fw);
        make.height.mas_equalTo(105);
        make.left.equalTo(self.mas_left).offset(30);
        make.top.equalTo(self.mas_top).offset(56);
    }];
//    self.notLab.hidden = NO;
}
#pragma mark - 点击箭头的方法
- (void)arrow_click{
    [self.delegate selectedDate:@"Class"];
}
#pragma mark - 添加子视图
- (void)addLittleSubView{
    for (int i = 0; i<2; i++) {
        CGFloat W = 204*fw;
        CGFloat H = 105*fh;
        CGFloat X = 15*(i+1)+W*i;
        CGFloat Y = 56*fh;
        HPClassCell *cell = [[HPClassCell alloc]initWithFrame:CGRectMake(X, Y, W, H)];
        cell.tag = 50+i;
        [self addSubview:cell];
    }
}
- (void)updateView{
    if (_dataArray.count == 0) {
        for (int i = 0; i<2; i++) {
            HPClassCell *cell = (HPClassCell *)[self viewWithTag:50+i];
            cell.hidden = YES;
        }
        self.notLab.hidden = NO;
        return;
    } else {
        self.notLab.hidden = YES;
    }
    for (int i = 0; i<_dataArray.count; i++) {
        HPClassCell *cell = (HPClassCell *)[self viewWithTag:50+i];
        cell.hidden = NO;
        cell.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0];
        HomeCourseModel *model = _dataArray[i];
        cell.titleLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:model.courseName attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
        cell.teacherLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.classroom attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];
        cell.otherLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.campusName attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0]}];
        cell.timeLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.attendDate attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0]}] ;
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goZuoYeView:)];
//        [cell addGestureRecognizer:tap];
    }
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0, 39)];
    [path addLineToPoint:CGPointMake(fw*452, 39)];
    [path setLineWidth:1];
    [LINCOLOR setStroke];
    [path stroke];
}
@end
